package oop.ex1.filters;

import java.io.File;
/**
 * a filter thats filters files by comparing it's prefix
 * @author danalmog
 * @author danielshalev
 */
public class Prefix extends NameDependent{
	
	/**
	 * construct a new prefix filter
	 * @param name the prefix we want to compare to
	 * @param hasNot determines if we should use as a NOT filter
	 */
	public Prefix(String name,boolean hasNot) {
		super(name,hasNot);
	}

	/**
	 * checks if the file has the desired prefix
	 * @param pathname the file we want to compare
	 * @return true if the file passed the filter, false otherwise
	 */
	public boolean accept(File pathname){
		if((pathname.getName().startsWith(getName()) && !hasNot) || (!pathname.getName().startsWith(getName()) && hasNot))
			return true;
		return false;
	}

}
